package com.zhipu.balance.ui.home.system.number.adapter

import android.annotation.SuppressLint
import android.graphics.Color
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.blankj.utilcode.util.TimeUtils
import com.zhipu.balance.databinding.ItemPersonnlBinding
import com.zhipu.balance.listener.AddItemOnClickListener
import com.zhipu.balance.mobile.event.Number


/**
 * 适配器编号管理
 */
class NumberManagementAdapter(private var mAddItemOnClickListener : AddItemOnClickListener) : RecyclerView.Adapter<NumberManagementAdapter.ItemViewHolder>() {

    private var mNumberList : List<Number>? = null
    fun setInspectionNumber(mNumberList: List<Number>){
        this.mNumberList = mNumberList
        notifyDataSetChanged()
    }



    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
        val binding = ItemPersonnlBinding.inflate(LayoutInflater.from(parent.context), parent, false)
        return ItemViewHolder(binding)
    }


    override fun onBindViewHolder(holder: ItemViewHolder, @SuppressLint("RecyclerView") position: Int) {
        var mNumber = mNumberList?.get(position)
        if(null != mNumber){

            if (mNumber.select) {
                holder.binding.Personnel.setBackgroundColor(Color.parseColor("#0684f8"))
            } else {
                holder.binding.Personnel.setBackgroundColor(Color.parseColor("#FFFFFF"))
            }

            holder.binding.inspectionPersonnelId.text = (position + 1).toString()
            holder.binding.name.text = mNumber.name
            holder.binding.establish.text = mNumber.creationTime?.let { TimeUtils.millis2String(it) }
            holder.binding.Personnel.setOnClickListener {
                mAddItemOnClickListener?.onSkipClicked(position,mNumber)
            }
        }
    }

    override fun getItemCount(): Int {
        return mNumberList!!.size
    }



    class ItemViewHolder(var binding: ItemPersonnlBinding) : RecyclerView.ViewHolder(binding.root) {
    }
}